package com.charles.seckillsystem.rocketMQ.producer;

import com.alibaba.fastjson2.JSONObject;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class OrderProducerImpl implements OrderProducer{
    
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    // 发送30分钟的延时消息
    // 这里的30分钟会稍微延后一点
    @Override
    public void checkOrder(Long userId, Long goodId) {
        Map<String, Long> map = new HashMap<>();
        map.put("userId", userId);
        map.put("goodId", goodId);
        
        rocketMQTemplate.syncSend("checkOrder", MessageBuilder.withPayload(JSONObject.toJSONString(map)).build(), 3000, 16);
    }
    
}
